<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActiveRecord::ConnectionAdapters::SchemaStatements</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/github.css" type="text/css" media="screen" />
<script src="../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Module</span> 
            ActiveRecord::ConnectionAdapters::SchemaStatements 
            
        </h1>
        <ul class="files">
            
            <li><a href="../../../files/activerecord/lib/active_record/connection_adapters/abstract/schema_statements_rb.html">activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>A</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-add_belongs_to">add_belongs_to</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-add_column">add_column</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-add_index">add_index</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-add_index_options">add_index_options</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-add_index_sort_order">add_index_sort_order</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-add_reference">add_reference</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-add_timestamps">add_timestamps</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-assume_migrated_upto_version">assume_migrated_upto_version</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>C</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-change_column">change_column</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-change_column_default">change_column_default</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-change_column_null">change_column_null</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-change_table">change_table</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-column_exists-3F">column_exists?</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-columns">columns</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-columns_for_remove">columns_for_remove</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-create_join_table">create_join_table</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-create_table">create_table</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>D</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-distinct">distinct</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-drop_join_table">drop_join_table</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-drop_table">drop_table</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>I</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-index_exists-3F">index_exists?</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-index_name_exists-3F">index_name_exists?</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-index_name_for_remove">index_name_for_remove</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-initialize_schema_migrations_table">initialize_schema_migrations_table</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>N</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-native_database_types">native_database_types</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>O</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-options_include_default-3F">options_include_default?</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>Q</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-quoted_columns_for_index">quoted_columns_for_index</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>R</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-remove_belongs_to">remove_belongs_to</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-remove_column">remove_column</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-remove_columns">remove_columns</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-remove_index">remove_index</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-remove_reference">remove_reference</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-remove_timestamps">remove_timestamps</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-rename_column">rename_column</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-rename_column_indexes">rename_column_indexes</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-rename_index">rename_index</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-rename_table">rename_table</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-rename_table_indexes">rename_table_indexes</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>T</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-table_alias_for">table_alias_for</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-table_exists-3F">table_exists?</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    


    


    <!-- Methods -->
        
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-add_belongs_to">
            
              <b>add_belongs_to</b>(table_name, ref_name, options = {})
            
            <a href="SchemaStatements.html#method-i-add_belongs_to" name="method-i-add_belongs_to" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-add_column">
            
              <b>add_column</b>(table_name, column_name, type, options = {})
            
            <a href="SchemaStatements.html#method-i-add_column" name="method-i-add_column" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Adds a new column to the named table. See <a
href="TableDefinition.html#method-i-column">ActiveRecord::ConnectionAdapters::TableDefinition#column</a>
for details of the options you can use.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-add_column_source')" id="l_method-i-add_column_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L357" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-add_column_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 357</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">add_column</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">column_name</span>, <span class="ruby-identifier">type</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-identifier">at</span> = <span class="ruby-identifier">create_alter_table</span> <span class="ruby-identifier">table_name</span>
  <span class="ruby-identifier">at</span>.<span class="ruby-identifier">add_column</span>(<span class="ruby-identifier">column_name</span>, <span class="ruby-identifier">type</span>, <span class="ruby-identifier">options</span>)
  <span class="ruby-identifier">execute</span> <span class="ruby-identifier">schema_creation</span>.<span class="ruby-identifier">accept</span> <span class="ruby-identifier">at</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-add_index">
            
              <b>add_index</b>(table_name, column_name, options = {})
            
            <a href="SchemaStatements.html#method-i-add_index" name="method-i-add_index" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Adds a new index to the table. <code>column_name</code> can be a single <a
href="../../Symbol.html">Symbol</a>, or an <a
href="../../Array.html">Array</a> of Symbols.</p>

<p>The index will be named after the table and the column name(s), unless you
pass <code>:name</code> as an option.</p>

<h6 id="method-i-add_index-label-Creating+a+simple+index">Creating a simple index</h6>

<pre>add_index(:suppliers, :name)</pre>

<p>generates:</p>

<pre>CREATE INDEX suppliers_name_index ON suppliers(name)</pre>

<h6 id="method-i-add_index-label-Creating+a+unique+index">Creating a unique index</h6>

<pre>add_index(:accounts, [:branch_id, :party_id], unique: true)</pre>

<p>generates:</p>

<pre>CREATE UNIQUE INDEX accounts_branch_id_party_id_index ON accounts(branch_id, party_id)</pre>

<h6 id="method-i-add_index-label-Creating+a+named+index">Creating a named index</h6>

<pre>add_index(:accounts, [:branch_id, :party_id], unique: true, name: 'by_branch_party')</pre>

<p>generates:</p>

<pre>CREATE UNIQUE INDEX by_branch_party ON accounts(branch_id, party_id)</pre>

<h6 id="method-i-add_index-label-Creating+an+index+with+specific+key+length">Creating an index with specific key length</h6>

<pre>add_index(:accounts, :name, name: 'by_name', length: 10)</pre>

<p>generates:</p>

<pre>CREATE INDEX by_name ON accounts(name(10))

add_index(:accounts, [:name, :surname], name: 'by_name_surname', length: {name: 10, surname: 15})</pre>

<p>generates:</p>

<pre>CREATE INDEX by_name_surname ON accounts(name(10), surname(15))</pre>

<p>Note: SQLite doesn’t support index length.</p>

<h6 id="method-i-add_index-label-Creating+an+index+with+a+sort+order+%28desc+or+asc%2C+asc+is+the+default%29">Creating an index with a sort order (desc or asc, asc is the default)</h6>

<pre>add_index(:accounts, [:branch_id, :party_id, :surname], order: {branch_id: :desc, party_id: :asc})</pre>

<p>generates:</p>

<pre>CREATE INDEX by_branch_desc_party ON accounts(branch_id DESC, party_id ASC, surname)</pre>

<p>Note: MySQL doesn’t yet support index order (it accepts the syntax but
ignores it).</p>

<h6 id="method-i-add_index-label-Creating+a+partial+index">Creating a partial index</h6>

<pre>add_index(:accounts, [:branch_id, :party_id], unique: true, where: &quot;active&quot;)</pre>

<p>generates:</p>

<pre>CREATE UNIQUE INDEX index_accounts_on_branch_id_and_party_id ON accounts(branch_id, party_id) WHERE active</pre>

<h6 id="method-i-add_index-label-Creating+an+index+with+a+specific+method">Creating an index with a specific method</h6>

<pre>add_index(:developers, :name, using: 'btree')</pre>

<p>generates:</p>

<pre>CREATE INDEX index_developers_on_name ON developers USING btree (name) -- PostgreSQL
CREATE INDEX index_developers_on_name USING btree ON developers (name) -- MySQL</pre>

<p>Note: only supported by PostgreSQL and MySQL</p>

<h6 id="method-i-add_index-label-Creating+an+index+with+a+specific+type">Creating an index with a specific type</h6>

<pre>add_index(:developers, :name, type: :fulltext)</pre>

<p>generates:</p>

<pre>CREATE FULLTEXT INDEX index_developers_on_name ON developers (name) -- MySQL</pre>

<p>Note: only supported by MySQL. Supported: <code>:fulltext</code> and
<code>:spatial</code> on MyISAM tables.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-add_index_source')" id="l_method-i-add_index_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L520" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-add_index_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 520</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">add_index</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">column_name</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-identifier">index_name</span>, <span class="ruby-identifier">index_type</span>, <span class="ruby-identifier">index_columns</span>, <span class="ruby-identifier">index_options</span> = <span class="ruby-identifier">add_index_options</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">column_name</span>, <span class="ruby-identifier">options</span>)
  <span class="ruby-identifier">execute</span> <span class="ruby-node">&quot;CREATE #{index_type} INDEX #{quote_column_name(index_name)} ON #{quote_table_name(table_name)} (#{index_columns})#{index_options}&quot;</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-add_reference">
            
              <b>add_reference</b>(table_name, ref_name, options = {})
            
            <a href="SchemaStatements.html#method-i-add_reference" name="method-i-add_reference" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Adds a reference. Optionally adds a <code>type</code> column, if
<code>:polymorphic</code> option is provided. <code>add_reference</code>
and <code>add_belongs_to</code> are acceptable.</p>

<h6 id="method-i-add_reference-label-Create+a+user_id+column">Create a user_id column</h6>

<pre>add_reference(:products, :user)</pre>

<h6 id="method-i-add_reference-label-Create+a+supplier_id+and+supplier_type+columns">Create a supplier_id and supplier_type columns</h6>

<pre>add_belongs_to(:products, :supplier, polymorphic: true)</pre>

<h6 id="method-i-add_reference-label-Create+a+supplier_id%2C+supplier_type+columns+and+appropriate+index">Create a supplier_id, supplier_type columns and appropriate index</h6>

<pre>add_reference(:products, :supplier, polymorphic: true, index: true)</pre>
            </div>
          
          
          
            <div class="aka">
              Also aliased as: <a href="SchemaStatements.html#method-i-add_belongs_to">add_belongs_to</a>
            </div>
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-add_reference_source')" id="l_method-i-add_reference_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L604" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-add_reference_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 604</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">add_reference</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">ref_name</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-identifier">polymorphic</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:polymorphic</span>)
  <span class="ruby-identifier">index_options</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:index</span>)
  <span class="ruby-identifier">add_column</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-node">&quot;#{ref_name}_id&quot;</span>, <span class="ruby-value">:integer</span>, <span class="ruby-identifier">options</span>)
  <span class="ruby-identifier">add_column</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-node">&quot;#{ref_name}_type&quot;</span>, <span class="ruby-value">:string</span>, <span class="ruby-identifier">polymorphic</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">polymorphic</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">options</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">polymorphic</span>
  <span class="ruby-identifier">add_index</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">polymorphic</span> <span class="ruby-operator">?</span> <span class="ruby-node">%w[id type]</span>.<span class="ruby-identifier">map</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span> <span class="ruby-node">&quot;#{ref_name}_#{t}&quot;</span> } <span class="ruby-operator">:</span> <span class="ruby-node">&quot;#{ref_name}_id&quot;</span>, <span class="ruby-identifier">index_options</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">index_options</span> <span class="ruby-operator">:</span> <span class="ruby-keyword">nil</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">index_options</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-add_timestamps">
            
              <b>add_timestamps</b>(table_name)
            
            <a href="SchemaStatements.html#method-i-add_timestamps" name="method-i-add_timestamps" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Adds timestamps (<code>created_at</code> and <code>updated_at</code>)
columns to the named table.</p>

<pre>add_timestamps(:suppliers)</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-add_timestamps_source')" id="l_method-i-add_timestamps_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L721" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-add_timestamps_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 721</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">add_timestamps</span>(<span class="ruby-identifier">table_name</span>)
  <span class="ruby-identifier">add_column</span> <span class="ruby-identifier">table_name</span>, <span class="ruby-value">:created_at</span>, <span class="ruby-value">:datetime</span>
  <span class="ruby-identifier">add_column</span> <span class="ruby-identifier">table_name</span>, <span class="ruby-value">:updated_at</span>, <span class="ruby-value">:datetime</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-assume_migrated_upto_version">
            
              <b>assume_migrated_upto_version</b>(version, migrations_paths = ActiveRecord::Migrator.migrations_paths)
            
            <a href="SchemaStatements.html#method-i-assume_migrated_upto_version" name="method-i-assume_migrated_upto_version" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-assume_migrated_upto_version_source')" id="l_method-i-assume_migrated_upto_version_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L644" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-assume_migrated_upto_version_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 644</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">assume_migrated_upto_version</span>(<span class="ruby-identifier">version</span>, <span class="ruby-identifier">migrations_paths</span> = <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Migrator</span>.<span class="ruby-identifier">migrations_paths</span>)
  <span class="ruby-identifier">migrations_paths</span> = <span class="ruby-constant">Array</span>(<span class="ruby-identifier">migrations_paths</span>)
  <span class="ruby-identifier">version</span> = <span class="ruby-identifier">version</span>.<span class="ruby-identifier">to_i</span>
  <span class="ruby-identifier">sm_table</span> = <span class="ruby-identifier">quote_table_name</span>(<span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Migrator</span>.<span class="ruby-identifier">schema_migrations_table_name</span>)

  <span class="ruby-identifier">migrated</span> = <span class="ruby-identifier">select_values</span>(<span class="ruby-node">&quot;SELECT version FROM #{sm_table}&quot;</span>).<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">v</span>.<span class="ruby-identifier">to_i</span> }
  <span class="ruby-identifier">paths</span> = <span class="ruby-identifier">migrations_paths</span>.<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">p</span><span class="ruby-operator">|</span> <span class="ruby-node">&quot;#{p}/[0-9]*_*.rb&quot;</span> }
  <span class="ruby-identifier">versions</span> = <span class="ruby-constant">Dir</span>[*<span class="ruby-identifier">paths</span>].<span class="ruby-identifier">map</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">filename</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">filename</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">'/'</span>).<span class="ruby-identifier">last</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">'_'</span>).<span class="ruby-identifier">first</span>.<span class="ruby-identifier">to_i</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">unless</span> <span class="ruby-identifier">migrated</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">version</span>)
    <span class="ruby-identifier">execute</span> <span class="ruby-node">&quot;INSERT INTO #{sm_table} (version) VALUES ('#{version}')&quot;</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">inserted</span> = <span class="ruby-constant">Set</span>.<span class="ruby-identifier">new</span>
  (<span class="ruby-identifier">versions</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">migrated</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">inserted</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">v</span>)
      <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;Duplicate migration #{v}. Please renumber your migrations to resolve the conflict.&quot;</span>
    <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">v</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">version</span>
      <span class="ruby-identifier">execute</span> <span class="ruby-node">&quot;INSERT INTO #{sm_table} (version) VALUES ('#{v}')&quot;</span>
      <span class="ruby-identifier">inserted</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">v</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-change_column">
            
              <b>change_column</b>(table_name, column_name, type, options = {})
            
            <a href="SchemaStatements.html#method-i-change_column" name="method-i-change_column" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Changes the column’s definition according to the new options. See <a
href="TableDefinition.html#method-i-column">ActiveRecord::ConnectionAdapters::TableDefinition#column</a>
for details of the options you can use.</p>

<pre>change_column(:suppliers, :name, :string, limit: 80)
change_column(:accounts, :description, :text)</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-change_column_source')" id="l_method-i-change_column_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L391" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-change_column_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 391</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">change_column</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">column_name</span>, <span class="ruby-identifier">type</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">NotImplementedError</span>, <span class="ruby-string">&quot;change_column is not implemented&quot;</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-change_column_default">
            
              <b>change_column_default</b>(table_name, column_name, default)
            
            <a href="SchemaStatements.html#method-i-change_column_default" name="method-i-change_column_default" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Sets a new default value for a column:</p>

<pre>change_column_default(:suppliers, :qualification, 'new')
change_column_default(:accounts, :authorized, 1)</pre>

<p>Setting the default to <code>nil</code> effectively drops the default:</p>

<pre>change_column_default(:users, :email, nil)</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-change_column_default_source')" id="l_method-i-change_column_default_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L404" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-change_column_default_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 404</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">change_column_default</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">column_name</span>, <span class="ruby-identifier">default</span>)
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">NotImplementedError</span>, <span class="ruby-string">&quot;change_column_default is not implemented&quot;</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-change_column_null">
            
              <b>change_column_null</b>(table_name, column_name, null, default = nil)
            
            <a href="SchemaStatements.html#method-i-change_column_null" name="method-i-change_column_null" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Sets or removes a +NOT NULL+ constraint on a column. The <code>null</code>
flag indicates whether the value can be <code>NULL</code>. For example</p>

<pre>change_column_null(:users, :nickname, false)</pre>

<p>says nicknames cannot be <code>NULL</code> (adds the constraint), whereas</p>

<pre>change_column_null(:users, :nickname, true)</pre>

<p>allows them to be <code>NULL</code> (drops the constraint).</p>

<p>The method accepts an optional fourth argument to replace existing +NULL+s
with some other value. Use that one when enabling the constraint if needed,
since otherwise those rows would not be valid.</p>

<p>Please note the fourth argument does not set a column’s default.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-change_column_null_source')" id="l_method-i-change_column_null_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L424" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-change_column_null_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 424</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">change_column_null</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">column_name</span>, <span class="ruby-identifier">null</span>, <span class="ruby-identifier">default</span> = <span class="ruby-keyword">nil</span>)
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">NotImplementedError</span>, <span class="ruby-string">&quot;change_column_null is not implemented&quot;</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-change_table">
            
              <b>change_table</b>(table_name, options = {})
            
            <a href="SchemaStatements.html#method-i-change_table" name="method-i-change_table" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>A block for changing columns in <code>table</code>.</p>

<pre class="ruby"><span class="ruby-comment"># change_table() yields a Table instance</span>
<span class="ruby-identifier">change_table</span>(:<span class="ruby-identifier">suppliers</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">t</span>.<span class="ruby-identifier">column</span> :<span class="ruby-identifier">name</span>, :<span class="ruby-identifier">string</span>, <span class="ruby-identifier">limit</span><span class="ruby-operator">:</span> <span class="ruby-value">60</span>
  <span class="ruby-comment"># Other column alterations here</span>
<span class="ruby-keyword">end</span>
</pre>

<p>The <code>options</code> hash can include the following keys:</p>
<dl class="rdoc-list label-list"><dt><code>:bulk</code>
<dd>
<p>Set this to true to make this a bulk alter query, such as</p>

<pre>ALTER TABLE `users` ADD COLUMN age INT(11), ADD COLUMN birthdate DATETIME ...</pre>

<p>Defaults to false.</p>
</dd></dl>

<h6 id="method-i-change_table-label-Add+a+column">Add a column</h6>

<pre class="ruby"><span class="ruby-identifier">change_table</span>(:<span class="ruby-identifier">suppliers</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">t</span>.<span class="ruby-identifier">column</span> :<span class="ruby-identifier">name</span>, :<span class="ruby-identifier">string</span>, <span class="ruby-identifier">limit</span><span class="ruby-operator">:</span> <span class="ruby-value">60</span>
<span class="ruby-keyword">end</span>
</pre>

<h6 id="method-i-change_table-label-Add+2+integer+columns">Add 2 integer columns</h6>

<pre class="ruby"><span class="ruby-identifier">change_table</span>(:<span class="ruby-identifier">suppliers</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">t</span>.<span class="ruby-identifier">integer</span> :<span class="ruby-identifier">width</span>, :<span class="ruby-identifier">height</span>, <span class="ruby-identifier">null</span><span class="ruby-operator">:</span> <span class="ruby-keyword">false</span>, <span class="ruby-identifier">default</span><span class="ruby-operator">:</span> <span class="ruby-value">0</span>
<span class="ruby-keyword">end</span>
</pre>

<h6 id="method-i-change_table-label-Add+created_at%2Fupdated_at+columns">Add created_at/updated_at columns</h6>

<pre class="ruby"><span class="ruby-identifier">change_table</span>(:<span class="ruby-identifier">suppliers</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">t</span>.<span class="ruby-identifier">timestamps</span>
<span class="ruby-keyword">end</span>
</pre>

<h6 id="method-i-change_table-label-Add+a+foreign+key+column">Add a foreign key column</h6>

<pre class="ruby"><span class="ruby-identifier">change_table</span>(:<span class="ruby-identifier">suppliers</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">t</span>.<span class="ruby-identifier">references</span> :<span class="ruby-identifier">company</span>
<span class="ruby-keyword">end</span>
</pre>

<p>Creates a <code>company_id(integer)</code> column.</p>

<h6 id="method-i-change_table-label-Add+a+polymorphic+foreign+key+column">Add a polymorphic foreign key column</h6>

<pre class="ruby"><span class="ruby-identifier">change_table</span>(:<span class="ruby-identifier">suppliers</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">t</span>.<span class="ruby-identifier">belongs_to</span> :<span class="ruby-identifier">company</span>, <span class="ruby-identifier">polymorphic</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>
<span class="ruby-keyword">end</span>
</pre>

<p>Creates <code>company_type(varchar)</code> and
<code>company_id(integer)</code> columns.</p>

<h6 id="method-i-change_table-label-Remove+a+column">Remove a column</h6>

<pre class="ruby"><span class="ruby-identifier">change_table</span>(:<span class="ruby-identifier">suppliers</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">t</span>.<span class="ruby-identifier">remove</span> :<span class="ruby-identifier">company</span>
<span class="ruby-keyword">end</span>
</pre>

<h6 id="method-i-change_table-label-Remove+several+columns">Remove several columns</h6>

<pre class="ruby"><span class="ruby-identifier">change_table</span>(:<span class="ruby-identifier">suppliers</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">t</span>.<span class="ruby-identifier">remove</span> :<span class="ruby-identifier">company_id</span>
  <span class="ruby-identifier">t</span>.<span class="ruby-identifier">remove</span> :<span class="ruby-identifier">width</span>, :<span class="ruby-identifier">height</span>
<span class="ruby-keyword">end</span>
</pre>

<h6 id="method-i-change_table-label-Remove+an+index">Remove an index</h6>

<pre class="ruby"><span class="ruby-identifier">change_table</span>(:<span class="ruby-identifier">suppliers</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">t</span>.<span class="ruby-identifier">remove_index</span> :<span class="ruby-identifier">company_id</span>
<span class="ruby-keyword">end</span>
</pre>

<p>See also <a href="Table.html">Table</a> for details on all of the various
column transformation.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-change_table_source')" id="l_method-i-change_table_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L328" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-change_table_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 328</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">change_table</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">supports_bulk_alter?</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:bulk</span>]
    <span class="ruby-identifier">recorder</span> = <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Migration</span><span class="ruby-operator">::</span><span class="ruby-constant">CommandRecorder</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword">self</span>)
    <span class="ruby-keyword">yield</span> <span class="ruby-identifier">update_table_definition</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">recorder</span>)
    <span class="ruby-identifier">bulk_change_table</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">recorder</span>.<span class="ruby-identifier">commands</span>)
  <span class="ruby-keyword">else</span>
    <span class="ruby-keyword">yield</span> <span class="ruby-identifier">update_table_definition</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-keyword">self</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-column_exists-3F">
            
              <b>column_exists?</b>(table_name, column_name, type = nil, options = {})
            
            <a href="SchemaStatements.html#method-i-column_exists-3F" name="method-i-column_exists-3F" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Checks to see if a column exists in a given table.</p>

<pre># Check a column exists
column_exists?(:suppliers, :name)

# Check a column exists of a particular type
column_exists?(:suppliers, :name, :string)

# Check a column exists with a specific definition
column_exists?(:suppliers, :name, :string, limit: 100)
column_exists?(:suppliers, :name, :string, default: 'default')
column_exists?(:suppliers, :name, :string, null: false)
column_exists?(:suppliers, :tax, :decimal, precision: 8, scale: 2)</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-column_exists-3F_source')" id="l_method-i-column_exists-3F_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L73" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-column_exists-3F_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 73</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">column_exists?</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">column_name</span>, <span class="ruby-identifier">type</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-identifier">columns</span>(<span class="ruby-identifier">table_name</span>).<span class="ruby-identifier">any?</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">name</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">column_name</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">&amp;&amp;</span>
                                (<span class="ruby-operator">!</span><span class="ruby-identifier">type</span>                     <span class="ruby-operator">||</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">type</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">type</span>) <span class="ruby-operator">&amp;&amp;</span>
                                (<span class="ruby-operator">!</span><span class="ruby-identifier">options</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-value">:limit</span>)     <span class="ruby-operator">||</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">limit</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:limit</span>]) <span class="ruby-operator">&amp;&amp;</span>
                                (<span class="ruby-operator">!</span><span class="ruby-identifier">options</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-value">:precision</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">precision</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:precision</span>]) <span class="ruby-operator">&amp;&amp;</span>
                                (<span class="ruby-operator">!</span><span class="ruby-identifier">options</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-value">:scale</span>)     <span class="ruby-operator">||</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">scale</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:scale</span>]) <span class="ruby-operator">&amp;&amp;</span>
                                (<span class="ruby-operator">!</span><span class="ruby-identifier">options</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-value">:default</span>)   <span class="ruby-operator">||</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">default</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:default</span>]) <span class="ruby-operator">&amp;&amp;</span>
                                (<span class="ruby-operator">!</span><span class="ruby-identifier">options</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-value">:null</span>)      <span class="ruby-operator">||</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">null</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:null</span>]) }
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-columns">
            
              <b>columns</b>(table_name)
            
            <a href="SchemaStatements.html#method-i-columns" name="method-i-columns" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns an array of Column objects for the table specified by
<code>table_name</code>. See the concrete implementation for details on the
expected parameter values.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-columns_source')" id="l_method-i-columns_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L57" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-columns_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 57</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">columns</span>(<span class="ruby-identifier">table_name</span>) <span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-create_join_table">
            
              <b>create_join_table</b>(table_1, table_2, options = {})
            
            <a href="SchemaStatements.html#method-i-create_join_table" name="method-i-create_join_table" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Creates a new join table with the name created using the lexical order of
the first two arguments. These arguments can be a <a
href="../../String.html">String</a> or a <a
href="../../Symbol.html">Symbol</a>.</p>

<pre># Creates a table called 'assemblies_parts' with no id.
create_join_table(:assemblies, :parts)</pre>

<p>You can pass a <code>options</code> hash can include the following keys:</p>
<dl class="rdoc-list label-list"><dt><code>:table_name</code>
<dd>
<p>Sets the table name overriding the default</p>
</dd><dt><code>:column_options</code>
<dd>
<p>Any extra options you want appended to the columns definition.</p>
</dd><dt><code>:options</code>
<dd>
<p>Any extra options you want appended to the table definition.</p>
</dd><dt><code>:temporary</code>
<dd>
<p>Make a temporary table.</p>
</dd><dt><code>:force</code>
<dd>
<p>Set to true to drop the table before creating it. Defaults to false.</p>
</dd></dl>

<p>Note that <code>create_join_table</code> does not create any indices by
default; you can use its block form to do so yourself:</p>

<pre class="ruby"><span class="ruby-identifier">create_join_table</span> :<span class="ruby-identifier">products</span>, :<span class="ruby-identifier">categories</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">t</span>.<span class="ruby-identifier">index</span> :<span class="ruby-identifier">product_id</span>
  <span class="ruby-identifier">t</span>.<span class="ruby-identifier">index</span> :<span class="ruby-identifier">category_id</span>
<span class="ruby-keyword">end</span>
</pre>

<h6 id="method-i-create_join_table-label-Add+a+backend+specific+option+to+the+generated+SQL+%28MySQL%29">Add a backend specific option to the generated SQL (MySQL)</h6>

<pre>create_join_table(:assemblies, :parts, options: 'ENGINE=InnoDB DEFAULT CHARSET=utf8')</pre>

<p>generates:</p>

<pre>CREATE TABLE assemblies_parts (
  assembly_id int NOT NULL,
  part_id int NOT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=utf8</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-create_join_table_source')" id="l_method-i-create_join_table_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L232" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-create_join_table_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 232</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">create_join_table</span>(<span class="ruby-identifier">table_1</span>, <span class="ruby-identifier">table_2</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-identifier">join_table_name</span> = <span class="ruby-identifier">find_join_table_name</span>(<span class="ruby-identifier">table_1</span>, <span class="ruby-identifier">table_2</span>, <span class="ruby-identifier">options</span>)

  <span class="ruby-identifier">column_options</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:column_options</span>) <span class="ruby-operator">||</span> {}
  <span class="ruby-identifier">column_options</span>.<span class="ruby-identifier">reverse_merge!</span>(<span class="ruby-identifier">null</span><span class="ruby-operator">:</span> <span class="ruby-keyword">false</span>)

  <span class="ruby-identifier">t1_column</span>, <span class="ruby-identifier">t2_column</span> = [<span class="ruby-identifier">table_1</span>, <span class="ruby-identifier">table_2</span>].<span class="ruby-identifier">map</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span> <span class="ruby-identifier">t</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">singularize</span>.<span class="ruby-identifier">foreign_key</span> }

  <span class="ruby-identifier">create_table</span>(<span class="ruby-identifier">join_table_name</span>, <span class="ruby-identifier">options</span>.<span class="ruby-identifier">merge!</span>(<span class="ruby-identifier">id</span><span class="ruby-operator">:</span> <span class="ruby-keyword">false</span>)) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">td</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">td</span>.<span class="ruby-identifier">integer</span> <span class="ruby-identifier">t1_column</span>, <span class="ruby-identifier">column_options</span>
    <span class="ruby-identifier">td</span>.<span class="ruby-identifier">integer</span> <span class="ruby-identifier">t2_column</span>, <span class="ruby-identifier">column_options</span>
    <span class="ruby-keyword">yield</span> <span class="ruby-identifier">td</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">block_given?</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-create_table">
            
              <b>create_table</b>(table_name, options = {})
            
            <a href="SchemaStatements.html#method-i-create_table" name="method-i-create_table" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Creates a new table with the name <code>table_name</code>.
<code>table_name</code> may either be a <a
href="../../String.html">String</a> or a <a
href="../../Symbol.html">Symbol</a>.</p>

<p>There are two ways to work with <code>create_table</code>. You can use the
block form or the regular form, like this:</p>

<h3 id="method-i-create_table-label-Block+form">Block form</h3>

<pre class="ruby"><span class="ruby-comment"># create_table() passes a TableDefinition object to the block.</span>
<span class="ruby-comment"># This form will not only create the table, but also columns for the</span>
<span class="ruby-comment"># table.</span>

<span class="ruby-identifier">create_table</span>(:<span class="ruby-identifier">suppliers</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">t</span>.<span class="ruby-identifier">column</span> :<span class="ruby-identifier">name</span>, :<span class="ruby-identifier">string</span>, <span class="ruby-identifier">limit</span><span class="ruby-operator">:</span> <span class="ruby-value">60</span>
  <span class="ruby-comment"># Other fields here</span>
<span class="ruby-keyword">end</span>
</pre>

<h3 id="method-i-create_table-label-Block+form%2C+with+shorthand">Block form, with shorthand</h3>

<pre class="ruby"><span class="ruby-comment"># You can also use the column types as method calls, rather than calling the column method.</span>
<span class="ruby-identifier">create_table</span>(:<span class="ruby-identifier">suppliers</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">t</span>.<span class="ruby-identifier">string</span> :<span class="ruby-identifier">name</span>, <span class="ruby-identifier">limit</span><span class="ruby-operator">:</span> <span class="ruby-value">60</span>
  <span class="ruby-comment"># Other fields here</span>
<span class="ruby-keyword">end</span>
</pre>

<h3 id="method-i-create_table-label-Regular+form">Regular form</h3>

<pre># Creates a table called 'suppliers' with no columns.
create_table(:suppliers)
# Add a column to 'suppliers'.
add_column(:suppliers, :name, :string, {limit: 60})</pre>

<p>The <code>options</code> hash can include the following keys:</p>
<dl class="rdoc-list label-list"><dt><code>:id</code>
<dd>
<p>Whether to automatically add a primary key column. Defaults to true. Join
tables for <code>has_and_belongs_to_many</code> should set it to false.</p>
</dd><dt><code>:primary_key</code>
<dd>
<p>The name of the primary key, if one is to be added automatically. Defaults
to <code>id</code>. If <code>:id</code> is false this option is ignored.</p>

<p>Also note that this just sets the primary key in the table. You
additionally need to configure the primary key in the model via
<code>self.primary_key=</code>. Models do NOT auto-detect the primary key
from their table definition.</p>
</dd><dt><code>:options</code>
<dd>
<p>Any extra options you want appended to the table definition.</p>
</dd><dt><code>:temporary</code>
<dd>
<p>Make a temporary table.</p>
</dd><dt><code>:force</code>
<dd>
<p>Set to true to drop the table before creating it. Defaults to false.</p>
</dd></dl>

<h6 id="method-i-create_table-label-Add+a+backend+specific+option+to+the+generated+SQL+%28MySQL%29">Add a backend specific option to the generated SQL (MySQL)</h6>

<pre>create_table(:suppliers, options: 'ENGINE=InnoDB DEFAULT CHARSET=utf8')</pre>

<p>generates:</p>

<pre>CREATE TABLE suppliers (
  id int(11) DEFAULT NULL auto_increment PRIMARY KEY
) ENGINE=InnoDB DEFAULT CHARSET=utf8</pre>

<h6 id="method-i-create_table-label-Rename+the+primary+key+column">Rename the primary key column</h6>

<pre class="ruby"><span class="ruby-identifier">create_table</span>(:<span class="ruby-identifier">objects</span>, <span class="ruby-identifier">primary_key</span><span class="ruby-operator">:</span> <span class="ruby-string">'guid'</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">t</span>.<span class="ruby-identifier">column</span> :<span class="ruby-identifier">name</span>, :<span class="ruby-identifier">string</span>, <span class="ruby-identifier">limit</span><span class="ruby-operator">:</span> <span class="ruby-value">80</span>
<span class="ruby-keyword">end</span>
</pre>

<p>generates:</p>

<pre>CREATE TABLE objects (
  guid int(11) DEFAULT NULL auto_increment PRIMARY KEY,
  name varchar(80)
)</pre>

<h6 id="method-i-create_table-label-Do+not+add+a+primary+key+column">Do not add a primary key column</h6>

<pre class="ruby"><span class="ruby-identifier">create_table</span>(:<span class="ruby-identifier">categories_suppliers</span>, <span class="ruby-identifier">id</span><span class="ruby-operator">:</span> <span class="ruby-keyword">false</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">t</span>.<span class="ruby-identifier">column</span> :<span class="ruby-identifier">category_id</span>, :<span class="ruby-identifier">integer</span>
  <span class="ruby-identifier">t</span>.<span class="ruby-identifier">column</span> :<span class="ruby-identifier">supplier_id</span>, :<span class="ruby-identifier">integer</span>
<span class="ruby-keyword">end</span>
</pre>

<p>generates:</p>

<pre>CREATE TABLE categories_suppliers (
  category_id int,
  supplier_id int
)</pre>

<p>See also <a
href="TableDefinition.html#method-i-column">ActiveRecord::ConnectionAdapters::TableDefinition#column</a>
for details on how to create columns.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-create_table_source')" id="l_method-i-create_table_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L173" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-create_table_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 173</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">create_table</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-identifier">td</span> = <span class="ruby-identifier">create_table_definition</span> <span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">options</span>[<span class="ruby-value">:temporary</span>], <span class="ruby-identifier">options</span>[<span class="ruby-value">:options</span>]

  <span class="ruby-keyword">unless</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:id</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword">false</span>
    <span class="ruby-identifier">pk</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">fetch</span>(<span class="ruby-value">:primary_key</span>) {
      <span class="ruby-constant">Base</span>.<span class="ruby-identifier">get_primary_key</span> <span class="ruby-identifier">table_name</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">singularize</span>
    }

    <span class="ruby-identifier">td</span>.<span class="ruby-identifier">primary_key</span> <span class="ruby-identifier">pk</span>, <span class="ruby-identifier">options</span>.<span class="ruby-identifier">fetch</span>(<span class="ruby-value">:id</span>, <span class="ruby-value">:primary_key</span>), <span class="ruby-identifier">options</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">yield</span> <span class="ruby-identifier">td</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">block_given?</span>

  <span class="ruby-keyword">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:force</span>] <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">table_exists?</span>(<span class="ruby-identifier">table_name</span>)
    <span class="ruby-identifier">drop_table</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">options</span>)
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">execute</span> <span class="ruby-identifier">schema_creation</span>.<span class="ruby-identifier">accept</span> <span class="ruby-identifier">td</span>
  <span class="ruby-identifier">td</span>.<span class="ruby-identifier">indexes</span>.<span class="ruby-identifier">each_pair</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">c</span>,<span class="ruby-identifier">o</span><span class="ruby-operator">|</span> <span class="ruby-identifier">add_index</span> <span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">c</span>, <span class="ruby-identifier">o</span> }
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-distinct">
            
              <b>distinct</b>(columns, order_by)
            
            <a href="SchemaStatements.html#method-i-distinct" name="method-i-distinct" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>SELECT DISTINCT clause for a given set of columns and a given ORDER BY
clause. Both PostgreSQL and Oracle overrides this for custom DISTINCT
syntax.</p>

<pre>distinct(&quot;posts.id&quot;, &quot;posts.created_at desc&quot;)</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-distinct_source')" id="l_method-i-distinct_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L713" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-distinct_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 713</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">distinct</span>(<span class="ruby-identifier">columns</span>, <span class="ruby-identifier">order_by</span>)
  <span class="ruby-node">&quot;DISTINCT #{columns}&quot;</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-drop_join_table">
            
              <b>drop_join_table</b>(table_1, table_2, options = {})
            
            <a href="SchemaStatements.html#method-i-drop_join_table" name="method-i-drop_join_table" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Drops the join table specified by the given arguments. See
<code>create_join_table</code> for details.</p>

<p>Although this command ignores the block if one is given, it can be helpful
to provide one in a migration’s <code>change</code> method so it can be
reverted. In that case, the block will be used by create_join_table.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-drop_join_table_source')" id="l_method-i-drop_join_table_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L253" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-drop_join_table_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 253</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">drop_join_table</span>(<span class="ruby-identifier">table_1</span>, <span class="ruby-identifier">table_2</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-identifier">join_table_name</span> = <span class="ruby-identifier">find_join_table_name</span>(<span class="ruby-identifier">table_1</span>, <span class="ruby-identifier">table_2</span>, <span class="ruby-identifier">options</span>)
  <span class="ruby-identifier">drop_table</span>(<span class="ruby-identifier">join_table_name</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-drop_table">
            
              <b>drop_table</b>(table_name, options = {})
            
            <a href="SchemaStatements.html#method-i-drop_table" name="method-i-drop_table" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Drops a table from the database.</p>

<p>Although this command ignores <code>options</code> and the block if one is
given, it can be helpful to provide these in a migration’s
<code>change</code> method so it can be reverted. In that case,
<code>options</code> and the block will be used by create_table.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-drop_table_source')" id="l_method-i-drop_table_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L351" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-drop_table_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 351</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">drop_table</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-identifier">execute</span> <span class="ruby-node">&quot;DROP TABLE #{quote_table_name(table_name)}&quot;</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-index_exists-3F">
            
              <b>index_exists?</b>(table_name, column_name, options = {})
            
            <a href="SchemaStatements.html#method-i-index_exists-3F" name="method-i-index_exists-3F" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Checks to see if an index exists on a table for a given index definition.</p>

<pre># Check an index exists
index_exists?(:suppliers, :company_id)

# Check an index on multiple columns exists
index_exists?(:suppliers, [:company_id, :company_type])

# Check a unique index exists
index_exists?(:suppliers, :company_id, unique: true)

# Check an index with a custom name exists
index_exists?(:suppliers, :company_id, name: &quot;idx_company_id&quot;</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-index_exists-3F_source')" id="l_method-i-index_exists-3F_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L45" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-index_exists-3F_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 45</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">index_exists?</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">column_name</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-identifier">column_names</span> = <span class="ruby-constant">Array</span>(<span class="ruby-identifier">column_name</span>)
  <span class="ruby-identifier">index_name</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-value">:name</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:name</span>].<span class="ruby-identifier">to_s</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">index_name</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-value">:column</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">column_names</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:unique</span>]
    <span class="ruby-identifier">indexes</span>(<span class="ruby-identifier">table_name</span>).<span class="ruby-identifier">any?</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-identifier">i</span>.<span class="ruby-identifier">unique</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">i</span>.<span class="ruby-identifier">name</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">index_name</span> }
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">indexes</span>(<span class="ruby-identifier">table_name</span>).<span class="ruby-identifier">any?</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-identifier">i</span>.<span class="ruby-identifier">name</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">index_name</span> }
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-index_name_exists-3F">
            
              <b>index_name_exists?</b>(table_name, index_name, default)
            
            <a href="SchemaStatements.html#method-i-index_name_exists-3F" name="method-i-index_name_exists-3F" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Verifies the existence of an index with a given name.</p>

<p>The default argument is returned if the underlying implementation does not
define the indexes method, as there’s no way to determine the correct
answer in that case.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-index_name_exists-3F_source')" id="l_method-i-index_name_exists-3F_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L583" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-index_name_exists-3F_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 583</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">index_name_exists?</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">index_name</span>, <span class="ruby-identifier">default</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">default</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:indexes</span>)
  <span class="ruby-identifier">index_name</span> = <span class="ruby-identifier">index_name</span>.<span class="ruby-identifier">to_s</span>
  <span class="ruby-identifier">indexes</span>(<span class="ruby-identifier">table_name</span>).<span class="ruby-identifier">detect</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-identifier">i</span>.<span class="ruby-identifier">name</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">index_name</span> }
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-initialize_schema_migrations_table">
            
              <b>initialize_schema_migrations_table</b>()
            
            <a href="SchemaStatements.html#method-i-initialize_schema_migrations_table" name="method-i-initialize_schema_migrations_table" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Should not be called normally, but this operation is non-destructive. The
migrations module handles this automatically.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-initialize_schema_migrations_table_source')" id="l_method-i-initialize_schema_migrations_table_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L640" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-initialize_schema_migrations_table_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 640</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">initialize_schema_migrations_table</span>
  <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">SchemaMigration</span>.<span class="ruby-identifier">create_table</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-native_database_types">
            
              <b>native_database_types</b>()
            
            <a href="SchemaStatements.html#method-i-native_database_types" name="method-i-native_database_types" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a hash of mappings from the abstract data types to the native
database types. See <a
href="TableDefinition.html#method-i-column">ActiveRecord::ConnectionAdapters::TableDefinition#column</a>
for details on the recognized abstract data types.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-native_database_types_source')" id="l_method-i-native_database_types_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L11" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-native_database_types_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 11</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">native_database_types</span>
  {}
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-remove_belongs_to">
            
              <b>remove_belongs_to</b>(table_name, ref_name, options = {})
            
            <a href="SchemaStatements.html#method-i-remove_belongs_to" name="method-i-remove_belongs_to" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-remove_column">
            
              <b>remove_column</b>(table_name, column_name, type = nil, options = {})
            
            <a href="SchemaStatements.html#method-i-remove_column" name="method-i-remove_column" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Removes the column from the table definition.</p>

<pre>remove_column(:suppliers, :qualification)</pre>

<p>The <code>type</code> and <code>options</code> parameters will be ignored
if present. It can be helpful to provide these in a migration’s
<code>change</code> method so it can be reverted. In that case,
<code>type</code> and <code>options</code> will be used by add_column.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-remove_column_source')" id="l_method-i-remove_column_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L381" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-remove_column_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 381</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">remove_column</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">column_name</span>, <span class="ruby-identifier">type</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-identifier">execute</span> <span class="ruby-node">&quot;ALTER TABLE #{quote_table_name(table_name)} DROP #{quote_column_name(column_name)}&quot;</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-remove_columns">
            
              <b>remove_columns</b>(table_name, *column_names)
            
            <a href="SchemaStatements.html#method-i-remove_columns" name="method-i-remove_columns" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Removes the given columns from the table definition.</p>

<pre>remove_columns(:suppliers, :qualification, :experience)</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-remove_columns_source')" id="l_method-i-remove_columns_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L367" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-remove_columns_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 367</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">remove_columns</span>(<span class="ruby-identifier">table_name</span>, *<span class="ruby-identifier">column_names</span>)
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;You must specify at least one column name. Example: remove_columns(:people, :first_name)&quot;</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">column_names</span>.<span class="ruby-identifier">empty?</span>
  <span class="ruby-identifier">column_names</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">column_name</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">remove_column</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">column_name</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-remove_index">
            
              <b>remove_index</b>(table_name, options = {})
            
            <a href="SchemaStatements.html#method-i-remove_index" name="method-i-remove_index" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Removes the given index from the table.</p>

<p>Removes the <code>index_accounts_on_column</code> in the
<code>accounts</code> table.</p>

<pre>remove_index :accounts, :column</pre>

<p>Removes the index named <code>index_accounts_on_branch_id</code> in the
<code>accounts</code> table.</p>

<pre>remove_index :accounts, column: :branch_id</pre>

<p>Removes the index named
<code>index_accounts_on_branch_id_and_party_id</code> in the
<code>accounts</code> table.</p>

<pre>remove_index :accounts, column: [:branch_id, :party_id]</pre>

<p>Removes the index named <code>by_branch_party</code> in the
<code>accounts</code> table.</p>

<pre>remove_index :accounts, name: :by_branch_party</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-remove_index_source')" id="l_method-i-remove_index_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L543" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-remove_index_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 543</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">remove_index</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-identifier">remove_index!</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">index_name_for_remove</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">options</span>))
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-remove_reference">
            
              <b>remove_reference</b>(table_name, ref_name, options = {})
            
            <a href="SchemaStatements.html#method-i-remove_reference" name="method-i-remove_reference" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Removes the reference(s). Also removes a <code>type</code> column if one
exists. <code>remove_reference</code>, <code>remove_references</code> and
<code>remove_belongs_to</code> are acceptable.</p>

<h6 id="method-i-remove_reference-label-Remove+the+reference">Remove the reference</h6>

<pre>remove_reference(:products, :user, index: true)</pre>

<h6 id="method-i-remove_reference-label-Remove+polymorphic+reference">Remove polymorphic reference</h6>

<pre>remove_reference(:products, :supplier, polymorphic: true)</pre>
            </div>
          
          
          
            <div class="aka">
              Also aliased as: <a href="SchemaStatements.html#method-i-remove_belongs_to">remove_belongs_to</a>
            </div>
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-remove_reference_source')" id="l_method-i-remove_reference_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L624" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-remove_reference_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 624</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">remove_reference</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">ref_name</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-identifier">remove_column</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-node">&quot;#{ref_name}_id&quot;</span>)
  <span class="ruby-identifier">remove_column</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-node">&quot;#{ref_name}_type&quot;</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:polymorphic</span>]
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-remove_timestamps">
            
              <b>remove_timestamps</b>(table_name)
            
            <a href="SchemaStatements.html#method-i-remove_timestamps" name="method-i-remove_timestamps" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Removes the timestamp columns (<code>created_at</code> and
<code>updated_at</code>) from the table definition.</p>

<pre>remove_timestamps(:suppliers)</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-remove_timestamps_source')" id="l_method-i-remove_timestamps_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L730" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-remove_timestamps_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 730</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">remove_timestamps</span>(<span class="ruby-identifier">table_name</span>)
  <span class="ruby-identifier">remove_column</span> <span class="ruby-identifier">table_name</span>, <span class="ruby-value">:updated_at</span>
  <span class="ruby-identifier">remove_column</span> <span class="ruby-identifier">table_name</span>, <span class="ruby-value">:created_at</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-rename_column">
            
              <b>rename_column</b>(table_name, column_name, new_column_name)
            
            <a href="SchemaStatements.html#method-i-rename_column" name="method-i-rename_column" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Renames a column.</p>

<pre>rename_column(:suppliers, :description, :name)</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-rename_column_source')" id="l_method-i-rename_column_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L432" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-rename_column_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 432</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">rename_column</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">column_name</span>, <span class="ruby-identifier">new_column_name</span>)
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">NotImplementedError</span>, <span class="ruby-string">&quot;rename_column is not implemented&quot;</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-rename_index">
            
              <b>rename_index</b>(table_name, old_name, new_name)
            
            <a href="SchemaStatements.html#method-i-rename_index" name="method-i-rename_index" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Renames an index.</p>

<p>Rename the <code>index_people_on_last_name</code> index to
<code>index_users_on_last_name</code>:</p>

<pre>rename_index :people, 'index_people_on_last_name', 'index_users_on_last_name'</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-rename_index_source')" id="l_method-i-rename_index_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L557" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-rename_index_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 557</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">rename_index</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">old_name</span>, <span class="ruby-identifier">new_name</span>)
  <span class="ruby-comment"># this is a naive implementation; some DBs may support this more efficiently (Postgres, for instance)</span>
  <span class="ruby-identifier">old_index_def</span> = <span class="ruby-identifier">indexes</span>(<span class="ruby-identifier">table_name</span>).<span class="ruby-identifier">detect</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-identifier">i</span>.<span class="ruby-identifier">name</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">old_name</span> }
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">old_index_def</span>
  <span class="ruby-identifier">remove_index</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-value">:name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">old_name</span>)
  <span class="ruby-identifier">add_index</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">old_index_def</span>.<span class="ruby-identifier">columns</span>, <span class="ruby-value">:name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">new_name</span>, <span class="ruby-value">:unique</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">old_index_def</span>.<span class="ruby-identifier">unique</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-rename_table">
            
              <b>rename_table</b>(table_name, new_name)
            
            <a href="SchemaStatements.html#method-i-rename_table" name="method-i-rename_table" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Renames a table.</p>

<pre>rename_table('octopuses', 'octopi')</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-rename_table_source')" id="l_method-i-rename_table_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L342" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-rename_table_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 342</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">rename_table</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">new_name</span>)
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">NotImplementedError</span>, <span class="ruby-string">&quot;rename_table is not implemented&quot;</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-table_alias_for">
            
              <b>table_alias_for</b>(table_name)
            
            <a href="SchemaStatements.html#method-i-table_alias_for" name="method-i-table_alias_for" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Truncates a table alias according to the limits of the current adapter.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-table_alias_for_source')" id="l_method-i-table_alias_for_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L16" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-table_alias_for_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 16</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">table_alias_for</span>(<span class="ruby-identifier">table_name</span>)
  <span class="ruby-identifier">table_name</span>[<span class="ruby-number">0</span><span class="ruby-operator">...</span><span class="ruby-identifier">table_alias_length</span>].<span class="ruby-identifier">tr</span>(<span class="ruby-string">'.'</span>, <span class="ruby-string">'_'</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-table_exists-3F">
            
              <b>table_exists?</b>(table_name)
            
            <a href="SchemaStatements.html#method-i-table_exists-3F" name="method-i-table_exists-3F" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Checks to see if the table <code>table_name</code> exists on the database.</p>

<pre>table_exists?(:developers)</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-table_exists-3F_source')" id="l_method-i-table_exists-3F_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L24" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-table_exists-3F_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 24</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">table_exists?</span>(<span class="ruby-identifier">table_name</span>)
  <span class="ruby-identifier">tables</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">table_name</span>.<span class="ruby-identifier">to_s</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
              
      <div class="sectiontitle">Instance Protected methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-add_index_options">
            
              <b>add_index_options</b>(table_name, column_name, options = {})
            
            <a href="SchemaStatements.html#method-i-add_index_options" name="method-i-add_index_options" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-add_index_options_source')" id="l_method-i-add_index_options_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L765" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-add_index_options_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 765</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">add_index_options</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">column_name</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-identifier">column_names</span> = <span class="ruby-constant">Array</span>(<span class="ruby-identifier">column_name</span>)
  <span class="ruby-identifier">index_name</span>   = <span class="ruby-identifier">index_name</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">column</span><span class="ruby-operator">:</span> <span class="ruby-identifier">column_names</span>)

  <span class="ruby-keyword">if</span> <span class="ruby-constant">Hash</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">options</span> <span class="ruby-comment"># legacy support, since this param was a string</span>
    <span class="ruby-identifier">options</span>.<span class="ruby-identifier">assert_valid_keys</span>(<span class="ruby-value">:unique</span>, <span class="ruby-value">:order</span>, <span class="ruby-value">:name</span>, <span class="ruby-value">:where</span>, <span class="ruby-value">:length</span>, <span class="ruby-value">:internal</span>, <span class="ruby-value">:using</span>, <span class="ruby-value">:algorithm</span>, <span class="ruby-value">:type</span>)

    <span class="ruby-identifier">index_type</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:unique</span>] <span class="ruby-operator">?</span> <span class="ruby-string">&quot;UNIQUE&quot;</span> <span class="ruby-operator">:</span> <span class="ruby-string">&quot;&quot;</span>
    <span class="ruby-identifier">index_type</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:type</span>].<span class="ruby-identifier">to_s</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">options</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-value">:type</span>)
    <span class="ruby-identifier">index_name</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:name</span>].<span class="ruby-identifier">to_s</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">options</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-value">:name</span>)
    <span class="ruby-identifier">max_index_length</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">fetch</span>(<span class="ruby-value">:internal</span>, <span class="ruby-keyword">false</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">index_name_length</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">allowed_index_name_length</span>

    <span class="ruby-keyword">if</span> <span class="ruby-identifier">options</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-value">:algorithm</span>)
      <span class="ruby-identifier">algorithm</span> = <span class="ruby-identifier">index_algorithms</span>.<span class="ruby-identifier">fetch</span>(<span class="ruby-identifier">options</span>[<span class="ruby-value">:algorithm</span>]) {
        <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">&quot;Algorithm must be one of the following: #{index_algorithms.keys.map(&amp;:inspect).join(', ')}&quot;</span>)
      }
    <span class="ruby-keyword">end</span>

    <span class="ruby-identifier">using</span> = <span class="ruby-node">&quot;USING #{options[:using]}&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:using</span>].<span class="ruby-identifier">present?</span>

    <span class="ruby-keyword">if</span> <span class="ruby-identifier">supports_partial_index?</span>
      <span class="ruby-identifier">index_options</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:where</span>] <span class="ruby-operator">?</span> <span class="ruby-node">&quot; WHERE #{options[:where]}&quot;</span> <span class="ruby-operator">:</span> <span class="ruby-string">&quot;&quot;</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">options</span>
      <span class="ruby-identifier">message</span> = <span class="ruby-string">&quot;Passing a string as third argument of `add_index` is deprecated and will&quot;</span> <span class="ruby-operator">+</span>
        <span class="ruby-string">&quot; be removed in Rails 4.1.&quot;</span> <span class="ruby-operator">+</span>
        <span class="ruby-node">&quot; Use add_index(#{table_name.inspect}, #{column_name.inspect}, unique: true) instead&quot;</span>

      <span class="ruby-constant">ActiveSupport</span><span class="ruby-operator">::</span><span class="ruby-constant">Deprecation</span>.<span class="ruby-identifier">warn</span> <span class="ruby-identifier">message</span>
    <span class="ruby-keyword">end</span>

    <span class="ruby-identifier">index_type</span> = <span class="ruby-identifier">options</span>
    <span class="ruby-identifier">max_index_length</span> = <span class="ruby-identifier">allowed_index_name_length</span>
    <span class="ruby-identifier">algorithm</span> = <span class="ruby-identifier">using</span> = <span class="ruby-keyword">nil</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">if</span> <span class="ruby-identifier">index_name</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">max_index_length</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;Index name '#{index_name}' on table '#{table_name}' is too long; the limit is #{max_index_length} characters&quot;</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">index_name_exists?</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">index_name</span>, <span class="ruby-keyword">false</span>)
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;Index name '#{index_name}' on table '#{table_name}' already exists&quot;</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">index_columns</span> = <span class="ruby-identifier">quoted_columns_for_index</span>(<span class="ruby-identifier">column_names</span>, <span class="ruby-identifier">options</span>).<span class="ruby-identifier">join</span>(<span class="ruby-string">&quot;, &quot;</span>)

  [<span class="ruby-identifier">index_name</span>, <span class="ruby-identifier">index_type</span>, <span class="ruby-identifier">index_columns</span>, <span class="ruby-identifier">index_options</span>, <span class="ruby-identifier">algorithm</span>, <span class="ruby-identifier">using</span>]
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-add_index_sort_order">
            
              <b>add_index_sort_order</b>(option_strings, column_names, options = {})
            
            <a href="SchemaStatements.html#method-i-add_index_sort_order" name="method-i-add_index_sort_order" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-add_index_sort_order_source')" id="l_method-i-add_index_sort_order_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L736" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-add_index_sort_order_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 736</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">add_index_sort_order</span>(<span class="ruby-identifier">option_strings</span>, <span class="ruby-identifier">column_names</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">options</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">order</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:order</span>]
    <span class="ruby-keyword">case</span> <span class="ruby-identifier">order</span>
    <span class="ruby-keyword">when</span> <span class="ruby-constant">Hash</span>
      <span class="ruby-identifier">column_names</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">name</span><span class="ruby-operator">|</span> <span class="ruby-identifier">option_strings</span>[<span class="ruby-identifier">name</span>] <span class="ruby-operator">+=</span> <span class="ruby-node">&quot; #{order[name].upcase}&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">order</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">name</span>)}
    <span class="ruby-keyword">when</span> <span class="ruby-constant">String</span>
      <span class="ruby-identifier">column_names</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">name</span><span class="ruby-operator">|</span> <span class="ruby-identifier">option_strings</span>[<span class="ruby-identifier">name</span>] <span class="ruby-operator">+=</span> <span class="ruby-node">&quot; #{order.upcase}&quot;</span>}
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">return</span> <span class="ruby-identifier">option_strings</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-columns_for_remove">
            
              <b>columns_for_remove</b>(table_name, *column_names)
            
            <a href="SchemaStatements.html#method-i-columns_for_remove" name="method-i-columns_for_remove" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-columns_for_remove_source')" id="l_method-i-columns_for_remove_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L831" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-columns_for_remove_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 831</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">columns_for_remove</span>(<span class="ruby-identifier">table_name</span>, *<span class="ruby-identifier">column_names</span>)
  <span class="ruby-constant">ActiveSupport</span><span class="ruby-operator">::</span><span class="ruby-constant">Deprecation</span>.<span class="ruby-identifier">warn</span>(<span class="ruby-string">&quot;columns_for_remove is deprecated and will be removed in the future&quot;</span>)
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;You must specify at least one column name. Example: remove_columns(:people, :first_name)&quot;</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">column_names</span>.<span class="ruby-identifier">blank?</span>
  <span class="ruby-identifier">column_names</span>.<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">column_name</span><span class="ruby-operator">|</span> <span class="ruby-identifier">quote_column_name</span>(<span class="ruby-identifier">column_name</span>) }
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-index_name_for_remove">
            
              <b>index_name_for_remove</b>(table_name, options = {})
            
            <a href="SchemaStatements.html#method-i-index_name_for_remove" name="method-i-index_name_for_remove" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-index_name_for_remove_source')" id="l_method-i-index_name_for_remove_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L813" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-index_name_for_remove_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 813</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">index_name_for_remove</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-identifier">index_name</span> = <span class="ruby-identifier">index_name</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">options</span>)

  <span class="ruby-keyword">unless</span> <span class="ruby-identifier">index_name_exists?</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">index_name</span>, <span class="ruby-keyword">true</span>)
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">options</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">options</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-value">:name</span>)
      <span class="ruby-identifier">options_without_column</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">dup</span>
      <span class="ruby-identifier">options_without_column</span>.<span class="ruby-identifier">delete</span> <span class="ruby-value">:column</span>
      <span class="ruby-identifier">index_name_without_column</span> = <span class="ruby-identifier">index_name</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">options_without_column</span>)

      <span class="ruby-keyword">return</span> <span class="ruby-identifier">index_name_without_column</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">index_name_exists?</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">index_name_without_column</span>, <span class="ruby-keyword">false</span>)
    <span class="ruby-keyword">end</span>

    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;Index name '#{index_name}' on table '#{table_name}' does not exist&quot;</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">index_name</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-options_include_default-3F">
            
              <b>options_include_default?</b>(options)
            
            <a href="SchemaStatements.html#method-i-options_include_default-3F" name="method-i-options_include_default-3F" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-options_include_default-3F_source')" id="l_method-i-options_include_default-3F_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L761" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-options_include_default-3F_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 761</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">options_include_default?</span>(<span class="ruby-identifier">options</span>)
  <span class="ruby-identifier">options</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-value">:default</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span>(<span class="ruby-identifier">options</span>[<span class="ruby-value">:null</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword">false</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:default</span>].<span class="ruby-identifier">nil?</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-quoted_columns_for_index">
            
              <b>quoted_columns_for_index</b>(column_names, options = {})
            
            <a href="SchemaStatements.html#method-i-quoted_columns_for_index" name="method-i-quoted_columns_for_index" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Overridden by the mysql adapter for supporting index lengths</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-quoted_columns_for_index_source')" id="l_method-i-quoted_columns_for_index_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L750" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-quoted_columns_for_index_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 750</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">quoted_columns_for_index</span>(<span class="ruby-identifier">column_names</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-identifier">option_strings</span> = <span class="ruby-constant">Hash</span>[<span class="ruby-identifier">column_names</span>.<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">name</span><span class="ruby-operator">|</span> [<span class="ruby-identifier">name</span>, <span class="ruby-string">''</span>]}]

  <span class="ruby-comment"># add index sort order if supported</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">supports_index_sort_order?</span>
    <span class="ruby-identifier">option_strings</span> = <span class="ruby-identifier">add_index_sort_order</span>(<span class="ruby-identifier">option_strings</span>, <span class="ruby-identifier">column_names</span>, <span class="ruby-identifier">options</span>)
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">column_names</span>.<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">name</span><span class="ruby-operator">|</span> <span class="ruby-identifier">quote_column_name</span>(<span class="ruby-identifier">name</span>) <span class="ruby-operator">+</span> <span class="ruby-identifier">option_strings</span>[<span class="ruby-identifier">name</span>]}
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-rename_column_indexes">
            
              <b>rename_column_indexes</b>(table_name, column_name, new_column_name)
            
            <a href="SchemaStatements.html#method-i-rename_column_indexes" name="method-i-rename_column_indexes" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-rename_column_indexes_source')" id="l_method-i-rename_column_indexes_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L846" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-rename_column_indexes_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 846</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">rename_column_indexes</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">column_name</span>, <span class="ruby-identifier">new_column_name</span>)
  <span class="ruby-identifier">column_name</span>, <span class="ruby-identifier">new_column_name</span> = <span class="ruby-identifier">column_name</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-identifier">new_column_name</span>.<span class="ruby-identifier">to_s</span>
  <span class="ruby-identifier">indexes</span>(<span class="ruby-identifier">table_name</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">index</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">next</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">index</span>.<span class="ruby-identifier">columns</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">new_column_name</span>)
    <span class="ruby-identifier">old_columns</span> = <span class="ruby-identifier">index</span>.<span class="ruby-identifier">columns</span>.<span class="ruby-identifier">dup</span>
    <span class="ruby-identifier">old_columns</span>[<span class="ruby-identifier">old_columns</span>.<span class="ruby-identifier">index</span>(<span class="ruby-identifier">new_column_name</span>)] = <span class="ruby-identifier">column_name</span>
    <span class="ruby-identifier">generated_index_name</span> = <span class="ruby-identifier">index_name</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">column</span><span class="ruby-operator">:</span> <span class="ruby-identifier">old_columns</span>)
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">generated_index_name</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">index</span>.<span class="ruby-identifier">name</span>
      <span class="ruby-identifier">rename_index</span> <span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">generated_index_name</span>, <span class="ruby-identifier">index_name</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">column</span><span class="ruby-operator">:</span> <span class="ruby-identifier">index</span>.<span class="ruby-identifier">columns</span>)
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-rename_table_indexes">
            
              <b>rename_table_indexes</b>(table_name, new_name)
            
            <a href="SchemaStatements.html#method-i-rename_table_indexes" name="method-i-rename_table_indexes" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-rename_table_indexes_source')" id="l_method-i-rename_table_indexes_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c578278dcdb1848f5f2e38c622f5265bd3d22f19/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L837" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-rename_table_indexes_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 837</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">rename_table_indexes</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">new_name</span>)
  <span class="ruby-identifier">indexes</span>(<span class="ruby-identifier">new_name</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">index</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">generated_index_name</span> = <span class="ruby-identifier">index_name</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">column</span><span class="ruby-operator">:</span> <span class="ruby-identifier">index</span>.<span class="ruby-identifier">columns</span>)
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">generated_index_name</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">index</span>.<span class="ruby-identifier">name</span>
      <span class="ruby-identifier">rename_index</span> <span class="ruby-identifier">new_name</span>, <span class="ruby-identifier">generated_index_name</span>, <span class="ruby-identifier">index_name</span>(<span class="ruby-identifier">new_name</span>, <span class="ruby-identifier">column</span><span class="ruby-operator">:</span> <span class="ruby-identifier">index</span>.<span class="ruby-identifier">columns</span>)
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    